<?php header('Content-type:text/html;charset=utf-8');?>
<head>
	<meta charset='utf-8'/>
</head>
<a href='wufengtext.php?action=addPro'>添加产品</a><br/>
<a href='wufengtext.php?action=addProls'>批量添加产品</a><br/>
<a href='wufengtext.php?action=upPro'>修改产品信息</a><br/>
<a href='wufengtext.php?action=upSta'>修改产品状态</a><br/>
<a href='wufengtext.php?action=upInv'>修改产品库存</a><br/>

<a href='wufengtext.php?action=selPro'>查询单件产品</a><br/>
<a href='wufengtext.php?action=selProls'>查询产品列表</a><br/>


<a href='wufengtext.php?action=addUser'>添加会员</a><br/>
<a href='wufengtext.php?action=addUserls'>批量添加会员</a><br/>
<a href='wufengtext.php?action=upUser'>修改会员信息</a><br/>
<a href='wufengtext.php?action=upUserSta'>修改会员状态</a><br/>

<a href='wufengtext.php?action=selUser'>查询单个会员</a><br/>
<a href='wufengtext.php?action=selUserls'>查询会员列表</a><br/>
<?php
require_once 'auto_loader.php';//自动加载类文件
$action = @$_GET['action'];
switch ($action) {
	//=====================================
	case 'addPro':
		addPro();
		break;
	
	case 'addProls':
		addProls();
		break;
	
	case 'upPro':
		upPro();
		break;
	
	case 'upSta':
		upSta();
		break;
	
	case 'upInv':
		upInv();
		break;
	
	case 'selPro':
		selPro();
		break;
	
	case 'selProls':
		selProls();
		break;
	//==============================
	case 'addUser':
		addUser();
		break;
	
	case 'addUserls':
		addUserls();
		break;
		
	case 'upUser':
		upUser();
		break;
	
	case 'upUserSta':
		upUserSta();
		break;
		
	case 'selUser':
		selUser();
		break;
	
	case 'selUserls':
		selUserls();
		break;

	default:
		echo '测试开始...';
	break;
}

function addUser(){
	try {
		$obj = new UserModelClass;
		$array = array('tid'=>1,'name'=>'Galaxy','content'=>'三星 Galaxy Note 3','inventory'=>100);
		$res = $obj->add($array);
		echo '添加会员成功'.$res;
	} catch (Exception $e) {
		echo 'addUser:<br>'.$obj->dbError;
	}
}

function addUserls(){
	try {
		$obj = new UserModelClass;
		$array = array(
				array('tid'=>1,'name'=>'三星','content'=>'三星 Galaxy Note 4','inventory'=>50),
				array('tid'=>1,'name'=>'Note 5','content'=>'三星 Galaxy Note 5','inventory'=>20),
				array('tid'=>1,'name'=>'Galaxy_6','content'=>'三星 Galaxy Note 6','inventory'=>80)
		);
		$res = $obj->add($array);
		echo '批量添加会员成功';
		print_r($res);
	} catch (Exception $e) {
		echo 'addUserls:<br>'.$e->getMessage();
	}
}

function upUser(){
	try {
		$obj = new UserModelClass;
		$array = array('uname'=>'三星 Galaxy Note 6');
		$id = 1;
		$res = $obj->updateUser($array, $id);
		echo '修改会员信息成功'.$res;
	} catch (Exception $e) {
		echo 'upUser:<br>'.$e->getMessage();
	}
}

function upUserSta(){
	try {
		$obj = new UserModelClass;
		$status = 3;
		$type = 'level';
		$id = 2;
		$res = $obj->updateStatus($status, $type, $id);
		echo '修改会员状态成功'.$res;
	} catch (Exception $e) {
		echo 'upUserSta:<br>'.$e->getMessage();
	}
}

function selUser(){
	try {
		$obj = new UserModelClass;
		$field = '*';
		$where = 'id <= 5';
		$res = $obj->select($field,$where);
		echo '查询单个会员成功<br/>';
		print_r($res);
	} catch (Exception $e) {
		echo 'selUser:<br>'.$e->getMessage();
	}
}

function selUserls(){
	try {
		$obj = new UserModelClass;
		$field = '*';
		$where = 'level = 0';
		$order = 'id desc';
		$limit = '0,5';
		$res = $obj->selectList($field,$where,$order,$limit);
		echo '查询会员列表成功<br/><pre>';
		print_r($res);
		echo '<pre/>';
	} catch (Exception $e) {
		echo 'selUserls:<br>'.$e->getMessage();
	}
}
//==========================================================================================
function addPro(){
	try {
		$obj = new ProductModelClass;
		$array = array('tid'=>1,'name'=>'三星 Galaxy Note 3','content'=>'三星 Galaxy Note 3','inventory'=>100);
		$res = $obj->add($array);
		echo '添加产品成功'.$res;
	} catch (Exception $e) {
		echo 'addPro:<br>'.$e->getMessage();
	}
	
}

function addProls(){
	try {
		$obj = new ProductModelClass;
		$array = array(
				array('tid'=>1,'name'=>'三星 Galaxy Note 4','content'=>'三星 Galaxy Note 4','inventory'=>50),
				array('tid'=>1,'name'=>'三星 Galaxy Note 5','content'=>'三星 Galaxy Note 5','inventory'=>20),
				array('tid'=>1,'name'=>'三星 Galaxy Note 6','content'=>'三星 Galaxy Note 6','inventory'=>80)
		);
		$res = $obj->add($array);
		echo '批量添加产品成功';
		print_r($res);
	} catch (Exception $e) {
		echo 'addProls:<br>'.$e->getMessage();
	}
}

function upPro(){
	try {
		$obj = new ProductModelClass;
		$array = array('tid'=>2);
		$id = 1;
		$res = $obj->updatePro($array, $id);
		echo '修改产品信息成功'.$res;
	} catch (Exception $e) {
		echo 'upPro:<br>'.$e->getMessage();
	}
	
}

function upSta(){
	try {
		$obj = new ProductModelClass;
		$status = 1;
		$type = 'sj';
		$id = 2;
		$res = $obj->updateStatus($status, $type, $id);
		echo '修改产品状态成功'.$res;
	} catch (Exception $e) {
		echo 'upSta:<br>'.$e->getMessage();
	}
}

function upInv(){
	try {
		$obj = new ProductModelClass;
		$inventory = -30;
		$id = 1;
		$res = $obj->updateInventory($inventory, $id);
		echo '修改产品库存成功'.$res;
	} catch (Exception $e) {
		echo 'upInv:<br>'.$e->getMessage();
	}
	
}

function selPro(){
	try {
		$obj = new ProductModelClass;
		$field = '*';
		$where = 'id <= 5';
		$res = $obj->select($field,$where);
		echo '查询单件产品成功<br/>';
		print_r($res);
	} catch (Exception $e) {
		echo 'selPro:<br>'.$e->getMessage();
	}
}

function selProls(){
	try {
		$obj = new ProductModelClass;
		$field = '*';
		$where = 'tid = 1';
		$order = 'id desc';
		$limit = '0,5';
		$res = $obj->selectList($field,$where,$order,$limit);
		echo '查询产品列表成功<br/><pre>';
		print_r($res);
		echo '<pre/>';
	} catch (Exception $e) {
		echo 'selProls:<br>'.$e->getMessage();
	}
}
